package com.cn.test.regex;

import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExpressionDemo {
	/**
	 * java利用正则表达式做拆分和获取值的例子
	 * 
	 * @author 唐植超 ^_^
	 * 
	 */
	public static void main(String[] args) {
		//String text = "name=\"alvin1\",password=\"alvin2\",mail=\"alvin3\",sex=\"alvin4\"";
		//Pattern pa = Pattern.compile(".+=\"(.+)\"");
		
		String text = "lvBlogContent.id=102&utm_source=dianshibao&utm_medium=email&utm_campaign=201306-19";
		Pattern pa = Pattern.compile("utm_medium=(.*?)&");
		
		Matcher ma = pa.matcher(text);
		//do {
			/*int end = text.indexOf(",");
			if (end > -1)
				ma.region(0, end);
			if (!ma.matches())
				break;
			System.out.println(ma.group(1));
			if (end == -1)
				break;
			text = text.substring(end + 1);
			ma = ma.reset(text);*/
			//System.out.println(ma.group(0));
		//} while (true);
		if (ma.find()) {
			MatchResult mr = ma.toMatchResult();
			System.out.println(mr.group(1));
		}
	}

}

